#!/usr/bin/env bash
set -e

TARGET_FILE=$1

if [ -z "${TARGET_FILE}" ];then
  TARGET_FILE="/app/index.html"
fi

echo "Start setup app-config.js hash suffix"
HASH=$(date +%s%N |md5sum | cut -c 1-8)

case $(uname) in
Darwin)
  sed -i .bak "s/app-config.js?v=___.*___\"><\/script>/app-config.js?v=___${APP_VERSION}-${HASH}___\"><\/script>/g" "${TARGET_FILE}"
  ;;
Linux)
  sed -i  "s/app-config.js?v=___.*___\"><\/script>/app-config.js?v=___${APP_VERSION}-${HASH}___\"><\/script>/g" "${TARGET_FILE}"
  ;;
esac
